import Vue from 'vue'
import Vuex from 'vuex'
import { Toast } from 'vant';

Vue.use(Toast);
Vue.use(Vuex);
// 数据持久化
import persistedState from 'vuex-persistedstate'


export default new Vuex.Store({
  state: {
    // 存钱
    myMoney: 10,
    money: "0",
  },
  mutations: {
    // 输入值
    inputMoney(state, num) {
      console.log(num);
      state.money = num
    },

    // 充值
    addMoney(state, num) {
      if (num.indexOf(".") != -1) {

        return Toast('请输入整数！');
      } else {

        // 转化为数字
        // console.log(num, state.myMoney);

        state.myMoney += parseFloat(num);
        // console.log(parseFloat(mymoney));
        (state.myMoney).toFixed(2);
        return Toast('充值成功！');
      }
    },
    // 买票
    buyTicket(state, tnum) {

      (state.myMoney -= tnum).toFixed(2);

      // console.log(state.myMoney);

    }
  },
  actions: {
  },
  getters: {

  },
  modules: {
  },
  // 数据持久化
  plugins: [persistedState()]
})
